<?php

namespace app\api\model;

use app\common\model\RemindOrder as RemindOrderModel;

class RemindOrder extends RemindOrderModel
{
    public function user()
    {
        return $this->hasOne(User::class, 'user_id', 'user_id');
    }



    /**
     * 单条信息
     */
    public static function getByUserId($userId)
    {
        return self::where('user_id', $userId)->order('createtime desc')->whereIn('type', [1,3,4,5])->find();
    }

    /**
     * 是否有未读
     */
    public static function getReadingByUserId($userId)
    {
        return self::where('user_id', $userId)->where('reading', 0)->whereIn('type', [1,3,4,5])->count();
    }

    /**
     * 用户课程提醒
     */
    public static function getAllByUserId($userId, $size = 20)
    {
        return self::with(['courseOrder' => function ($query) {
            $query->with(['teacher' => function ($query) {
                $query->withCount('course');
            }]);
        }])->where('user_id', $userId)->whereIn('type', [1,3,4,5])->order('createtime desc')->paginate($size);
    }
}
